package com.ruiyian.bridge.opreations.controller;

import com.ruiyian.bridge.opreations.domain.TDeviceWarn;
import com.ruiyian.bridge.opreations.service.DeviceWarnService;
import com.ruiyian.common.annotation.Log;
import com.ruiyian.common.core.controller.BaseController;
import com.ruiyian.common.core.domain.AjaxResult;
import com.ruiyian.common.core.page.TableDataInfo;
import com.ruiyian.common.enums.BusinessType;
import com.ruiyian.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 设备报警Controller
 *
 * @author ruiyian
 * @date 2022-01-25
 */
@RestController
@RequestMapping("/bridge/opreation/device_warn")
public class DeviceWarnController extends BaseController
{
    @Autowired
    private DeviceWarnService tDeviceWarnService;

    /**
     * 查询设备报警列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TDeviceWarn tDeviceWarn)
    {
        startPage();
        List<TDeviceWarn> list = tDeviceWarnService.selectTDeviceWarnList(tDeviceWarn);
        return getDataTable(list);
    }

    /**
     * 导出设备报警列表
     */
    @PostMapping("/export")
    public AjaxResult export(@RequestBody  TDeviceWarn tDeviceWarn)
    {
        List<TDeviceWarn> list = tDeviceWarnService.selectTDeviceWarnList(tDeviceWarn);
        ExcelUtil<TDeviceWarn> util = new ExcelUtil<>(TDeviceWarn.class);
        return  util.exportExcel(list, "设备报警数据");
    }

    /**
     * 获取设备报警详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tDeviceWarnService.selectTDeviceWarnById(id));
    }

    /**
     * 新增设备报警
     */
    @Log(title = "设备报警", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TDeviceWarn tDeviceWarn)
    {
        return toAjax(tDeviceWarnService.insertTDeviceWarn(tDeviceWarn));
    }

    /**
     * 修改设备报警
     */
    @Log(title = "设备报警", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TDeviceWarn tDeviceWarn)
    {
        return toAjax(tDeviceWarnService.updateTDeviceWarn(tDeviceWarn));
    }

    /**
     * 删除设备报警
     */
    @Log(title = "设备报警", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tDeviceWarnService.deleteTDeviceWarnByIds(ids));
    }
}
